package main;
import creatures.*;
import java.util.ArrayList;

import spells.Spell;
import spells.StatusEffect;

//asdd

public class Creature extends Occupant {
	
	public int maxHealth; //maximum health
	public int maxMana; //maximum mana
	public int curHealth; //current health
	public int curMana; //current mana
	public int level; //level of creature
	public int gold; //amount of gold that creature is carrying
	
	public Weapon weapon1; //weapon of the creature
	public int armor; //armor value of the creature
		
	public int strength; //physical damage
	public int stamina; //health
	public int intelligence; //spell damage
	public int spirit; //regen
	
	public double movementSpeed = 0.5; //seconds it takes for creature to move one square
	
	public int ai;
	
	public ArrayList<Item> inventory; //list of items that the creature holds
	public ArrayList<Spell> spells; //list of spells
	public ArrayList<StatusEffect> buffs; //positive and negative status effects on the creature
	
	
	public Creature() {
		super();
		inventory=new ArrayList<Item>();
		buffs=new ArrayList<StatusEffect>();
	}
	
	public Creature(int x, int y, String n){
		super(x, y, n);
		super.changeOccImage("characterReal.gif");
		maxHealth=100;
		maxMana=100;
		curHealth=100;
		curMana=100;
		level=1;
		gold=0;
		
		weapon1=null;
		armor=0;
			
		strength=0; //physical damage
		stamina=0; //health
		intelligence=0; //spell damage
		spirit=0; //regen
		
		ai = 1;
		
		inventory=new ArrayList<Item>();
		spells=new ArrayList<Spell>();
		buffs=new ArrayList<StatusEffect>();
	}
	
	public Creature(int maxH, int str, int lvl, int arm){
		maxHealth=maxH;
		//maxMana=100;
		curHealth=100;
		//curMana=100;
		level=lvl;
		gold=0;
		
		weapon1=null;
		armor=arm;
			
		strength=str; //physical damage
		stamina=0; //health
		intelligence=0; //spell damage
		spirit=0; //regen
		
		ai = 1;
		
		inventory=null;
		buffs=null;
	}
	
	public int getArmor() {
		for (int i = 0; i < inventory.size(); i++) {
			if (inventory.get(i) instanceof Gear)
				armor += inventory.get(i).armorVal;
		}
		return armor;
	}//returns armor of creature
	
	public boolean checkDeath(){
		if(curHealth<=0){
			removeFromGrid();
			return true;
		}
		return false;
	}//checks to see if creature has 0 hp and is dead, and if so removes it from the grid
	
	public void displayHealth()
	{
		System.out.println(name+"'s health is now "+curHealth+"/"+maxHealth);
	}
	
	public void takeDamage(int d){
		changeHealth(-d);
	}//causes creature to lose d health
	
	public void changeHealth(int amount)
	{
		if(amount>0)
			curHealth += amount;
		else
			curHealth+=(amount-armor);
		if (curHealth < 0)
		{
			curHealth = 0;
		}
		if (curHealth > maxHealth)
		{
			curHealth = maxHealth;
		}
	}
	
	public void addStatus(StatusEffect statusEffect){
		buffs.add(statusEffect);
	}//adds a status effect to creature
	
	public void addSpell(Spell s){
		spells.add(s);
	}//adds a spell to creature's spell list
	
	public Spell findSpell(String s){
		for(Spell sp:spells){
			if(sp.getName().equals(s)){
				return sp;
			}//end if
		}//end for
		return null;
	}//end method
	
	public void ai(Creature e, Player you){
		if (ai == 1 ) {
			int xdif = Math.abs(e.x - you.x);
			int ydif = Math.abs(e.y - you.y);
	
			if (xdif > ydif) {
				if (you.x > e.x) {
					e.moveRight();
				}
				else {
					e.moveLeft();
				}
			}
			else {
				if (you.y > e.y) {
					e.moveUp();
				}
				else {
					e.moveDown();
				}
			}
		}
		else if (ai == 2) {
			int xdif = Math.abs(e.x - you.x);
			int ydif = Math.abs(e.y - you.y);
			if (Math.abs(xdif-ydif) < 4) {
				if (xdif > ydif) {
					if (you.x > e.x) {
						e.moveLeft();
					}
					else {
						e.moveRight();
					}
				}
				else {
					if (you.y > e.y) {
						e.moveDown();
					}
					else {
						e.moveUp();
					}
				}
			}
			else if (xdif > ydif) {
				if (you.x > e.x) {
					e.moveRight();
				}
				else {
					e.moveLeft();
				}
			}
			else {
				if (you.y > e.y) {
					e.moveUp();
				}
				else {
					e.moveDown();
				}
			}
		}
	}

	public int getAi() {
		return ai;
	}

	public void setAi(int ai) {
		this.ai = ai;
	}
	
}//end class

/*

Zones/Creatures

grassy plains
Ragged Nomad
Porcupine - Curl into ball: Big increase to armor, retaliation damage
Rabid Coyote
Coyote
Coyote Pup

savannah plains
Lion
Hyenas - disease debuff
Stampeding Elephant
Vulture - disease debuff

forests
Elf Archer
Treant / Angry Tree
Dryad
Nymph

lakes
Fish
Crocodiles

swamps
Spiders

jungles
Panther
Tiger
Shaman
Poisonous Snake

mountains/Icy
Ice mage
Snow Leopard
Ice Yeti

mountains/volcano
Lava Ooze
Fire mage
Dragon Whelp

*/